package vidas;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.Runnable;
import java.util.TreeMap;
import java.util.Vector;
import javax.swing.JFrame;


public class Lienzo extends Canvas implements WindowListener{
    
    protected Lienzo(){
        JFrame jf=new JFrame("Sim Trafic");         //le agrego un nombre al Frame
        jf.addWindowListener(this);
        jf.setLayout(null);
        jf.setBounds(20,20,600,600);
        jf.setBackground(Color.gray);
        setBounds(20,20,541,541);                   //tamaño de la pantalla
        setBackground(Color.blue);      
        jf.getContentPane().add(this);
        jf.setVisible(true);
       
    }  
    //si quiero montar algo hago lo q sigue
    
    @Override
    public void paint (Graphics g){
       for(int i0=0; i0<getF().size(); i0++)
        getF().get(i0).dibujate(g); 
      
       // g.setColor(Color.yellow);
       // g.fill3DRect(100,50,25,200,false);
       //reemplazo por f.dibuj 
    }
  
    private Vector<Figura> f= new Vector<Figura>();
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //p dibujar desde aqui hacemos
        
             
        Lienzo l= new Lienzo();
        TreeMap<Integer, Integer> tc = new TreeMap<Integer, Integer>();
        tc.put(38, 0);
        tc.put(40, 1);
        tc.put(37, 2);
        tc.put(39, 3);
        
        Figura ff=new Movil(250,480,20,40, Color.red, l,tc,false);
        l.getF().add(ff); //****
        l.addKeyListener(ff);
        
               
   //PAREDES DE LA CIUDAD
        //1 MANZANA
        l.getF().add(new ParedV(300,100,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedV(350,100,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(300,100,50,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(300,200,60,10,Color.yellow, l));
        l.repaint();

        //2 MANZANA
        l.getF().add(new ParedV(150,100,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedV(200,100,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(150,100,50,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(150,200,60,10,Color.yellow, l));
        l.repaint();

        //3 MANZANA
        l.getF().add(new ParedV(300,300,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedV(350,300,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(300,300,50,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(300,400,60,10,Color.yellow, l));
        l.repaint();

        //4 MANZANA
        l.getF().add(new ParedV(150,300,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedV(200,300,10,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(150,300,50,100,Color.yellow, l));
        l.repaint();
        l.getF().add(new ParedH(150,400,60,10,Color.yellow, l));
        l.repaint();


        //LIMITE DE LA CIUDAD
        l.getF().add(new ParedV(0,0,5,540, Color.black, l));
        l.repaint();
        l.getF().add(new ParedV(535,0,5,600, Color.BLACK, l)); 
        l.repaint();
        l.getF().add(new ParedH(0,0,540,5, Color.BLACK, l)); 
        l.repaint();
        l.getF().add(new ParedH(0,535,540,5, Color.BLACK, l)); 
        l.repaint();


        //BASE
        l.getF().add(new Origen(260,0,50,60,Color.WHITE,l));

        //Destino
        l.getF().add(new Origen(260,0,50,60,Color.WHITE,l));


        //  l.getF().add(new ParedV(0,30,5,200, Color.black, l, null));
        //  l.repaint();
        //  l.getF().add(new ParedV(0,20,5,200, Color.BLACK, l, null));
        // l.repaint();

    }

    public void windowOpened(WindowEvent e) {
        // throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosing(WindowEvent e) {
        // throw new UnsupportedOperationException("Not supported yet.");
        System.exit(0);
    }

    public void windowClosed(WindowEvent e) {
        //  throw new UnsupportedOperationException("Not supported yet.");
        System.exit(0);
    }

    public void windowIconified(WindowEvent e) {
        //  throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeiconified(WindowEvent e) {
        //    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowActivated(WindowEvent e) {
        //  throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeactivated(WindowEvent e) {
        // throw new UnsupportedOperationException("Not supported yet.");
    }

    public Vector<Figura> getF() {
        return f;
    }    
}
